package web.admin;

import org.apache.wicket.Component;
import org.apache.wicket.markup.html.panel.EmptyPanel;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.protocol.http.WebRequest;
import org.apache.wicket.protocol.http.WebRequestCycle;
import org.apache.wicket.spring.injection.annot.SpringBean;
import org.wicketstuff.annotation.mount.MountPath;
import service.facade.admin.ShopAdminService;

@MountPath(path = "AdminPage")
public class AdminPage extends AdminBasePage {

    private Panel empty = new EmptyPanel("current");
    private Panel currentPanel = empty;
    private Panel leftPanel = new EmptyPanel("left");
    private Panel rightPanel = new EmptyPanel("right");

    @SpringBean
    private ShopAdminService shopAdminService;

    public AdminPage() {
        super();
        //nastavi expiraci sessiony na 1 hodinu
        WebRequest request = (WebRequest) WebRequestCycle.get().getRequest();
        request.getHttpServletRequest().getSession().setMaxInactiveInterval(3600);

        empty.setOutputMarkupId(true);
        add(currentPanel);
    }

    @Override
    public IModel getPageTitle() {
        return new Model("Admin page");
    }

    @Override
    public IModel getDescription() {
        return new Model("Admin Page");
    }

    @Override
    public IModel getKeywords() {
        return new Model("Admin Page");
    }

    @Override
    protected Component newLeftColumnPanel(String id) {
        return leftPanel;
    }

    @Override
    protected Component newTopMenuPanel(String id) {
        return new AdminMenuPanel(id, this);
    }


    public void setLeftPanel(Panel panel) {
        panel.setMarkupId("left");
        this.leftPanel.replaceWith(panel);
        this.leftPanel = panel;
    }

    public void setRightPanel(Panel panel) {
        panel.setMarkupId("right");
        this.rightPanel.replaceWith(panel);
        this.rightPanel = panel;
    }

    public void setCurrentPanelTo(Panel panel) {
        panel.setMarkupId("current");
        this.currentPanel.replaceWith(panel);
        this.currentPanel = panel;
    }

    public void setCurrentPanelToEmpty() {
        this.currentPanel.replaceWith(empty);
        this.currentPanel = empty;
    }

    public void setLeftPanelToEmpty() {
        Panel empty = new EmptyPanel("left");
        this.leftPanel.replaceWith(empty);
        this.leftPanel = empty;
    }

    public Panel getCurrentPanel() {
        return currentPanel;
    }

    public Panel getLeftPanel() {
        return leftPanel;
    }

    public Panel getRightPanel() {
        return rightPanel;
    }
}



